package org.water.common.shiro;

import org.apache.shiro.crypto.hash.DefaultHashService;
import org.apache.shiro.crypto.hash.Hash;
import org.apache.shiro.crypto.hash.HashRequest;
import org.apache.shiro.util.ByteSource;

/**
 * 密码辅助器
 * @author qzy
 *
 */
public class ShiroPwdHelper {

	
	/**
	 * 密码加密
	 * @param cs 原始密码
	 * @param Salt 盐
	 * @return 返回32位数据
	 */
	public  static String getEncodePWD(String pwd,String Salt)
	{
		DefaultHashService hashService = new DefaultHashService(); //默认算法SHA-512
		hashService.setHashAlgorithmName("SHA-512");
		hashService.setHashIterations(20); //生成Hash值的迭代次数
		HashRequest request = new HashRequest.Builder()
		            .setAlgorithmName("MD5").setSource(ByteSource.Util.bytes(pwd))
		            .setSalt(ByteSource.Util.bytes(Salt)).setIterations(10).build();
		Hash hash=hashService.computeHash(request);
		return hash.toHex();
	}
}
